package day6;

import java.util.Scanner;

public class Employee {
    public String name;
    public int age;
    public String sex;
    public double money;

    public Employee(String name,int age,String sex,double money ){
         setName(name);
         setAge(age);
         setSex(sex);
         setMoney(money);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name!=null){
            this.name = name;
        }else {
            throw new IllegalArgumentException("姓名不能为空!");
        }
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age>1&&age<100){
            this.age = age;
        }else {
            System.out.println("年龄为1~100岁!输入不合法，默认18岁");
            this.age=18;
        }
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        if (sex.equals("男")||sex.equals("女")){
            this.sex = sex;
        }else {
            System.out.println("性别只能为那男或女!输入错误，默认为男");
            this.sex="男";
        }
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        if (money>1&&money<=20000){
            this.money = money;
        }else {
            System.out.println("工资必须在1到20000之间!默认5000");
            this.money=5000;
        }
    }
    public void print(){
        System.out.println("姓名："+name+",年龄："+age+",性别："+sex+",工资："+money);
    }

    public void addSal(){
        Scanner sc=new Scanner(System.in);
        System.out.print("想要加薪吗?（y/n）：");
        String s=sc.next();
        if ("y".equals(s)){
            System.out.print("请输入想要涨薪多少元：");
            double db=sc.nextDouble();
            if ((db+money)>20000){
                System.out.println("加薪后工资超过20000元，不能加薪");
            }else {
                System.out.println("涨薪"+db+"元，加薪后的工资为："+(db+money));
            }
        }else if ("n".equals(s)){
            return;
        }
    }

    public static void main(String[] args) {
        Employee ey=new Employee("张三",30,"男",15000);
        ey.print();
        ey.addSal();
    }
}
